package com.dst.controller;

import com.dst.eneity.User;
import com.dst.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/longinController")
public class LoginController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        String password = req.getParameter("password");
        UserServiceImpl userService = new UserServiceImpl();
        User login = userService.login(username, password);
        if(login!=null){
            Cookie cookie = new Cookie("denglu", username);
            resp.addCookie(cookie);
            resp.sendRedirect(req.getContextPath()+"/phone/selectAllController");
        }else {
            resp.sendRedirect(req.getContextPath()+"/phone/selectAllController");
        }
    }
}
